package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.*;

import util.TimeStamp;

import dao.TIpApplyDao;
import entity.TIpApply;

import bean.IpApplyForm;
import bean.IpApplyStatusDetailForm;

public class IpApplyStatusDetailAction extends Action {

    public ActionForward execute(ActionMapping map, ActionForm frm,
            HttpServletRequest request, HttpServletResponse response) {

        String applyId = (String) request.getParameter("id");
        Integer applyIdInt = Integer.valueOf(applyId);
        
        // 申請 ID でレコードを取得
        TIpApply statusDetail = TIpApplyDao.getIpApplyDetail(applyIdInt);
        
        IpApplyStatusDetailForm form = new IpApplyStatusDetailForm();
        // 申請状況
        String status = null;
        Integer statusInt = statusDetail.getStatus();
        switch (statusInt) {
        case 0:
            status = "申請中";
            break;
        case 1:
            status = "IP割り当て済み";
            break;
        case 2:
            status = "申請却下";
            break;
        default:
            status = "申請中";
            break;
        }
        form.setStatus(status);
        form.setPlace(statusDetail.getPlace());
        form.setMacAddress(statusDetail.getMacAddress());
        form.setIpAddress(statusDetail.getIpAddress());
        form.setMessage(statusDetail.getMessage());
        form.setApplyTime(TimeStamp.getTsString(statusDetail.getApplyTime()));
        form.setLastUpdateTime(TimeStamp.getTsString(statusDetail.getLastUpdateTime()));
        
        request.setAttribute("statusDetail", form);
        
        return map.findForward("success");

    }
}
